/* model */
import Field from "@model/entity/Field";
import { FieldTypeMappingEnum } from "@model/enum/FieldMappingEnum";
import Column from "@model/types/Column";
/* utils */
import { isUndefined } from "@src/util/type";

/** 
 * @description 表单字段列表 转换为 表格列
*/
function settingListFieldsToColumns(fields: Field[]) {
  return fields.map(settingListFieldToColumn)
}

/** 
 * @description 表单字段 转换为 表格列
*/
function settingListFieldToColumn(field: Field): Column {
  
  const show: boolean | string = isUndefined(field.show) ? true : Boolean(field.show)
  let sortable: string | boolean = false
  
  const formType = field.formType as FieldTypeMappingEnum
  const minWidth = 160;
  
  return {
    ...field,
    /** 
     * @description 表格列 标题
     * @default field.displayName
     * @type string
    */
    label: field.displayName,
    field: field.fieldName,
    /** 
     * @description 表格列 是否显示
     * -- 默认显示，除非设置为 false
     * @default true
     * @type boolean
    */
    show,
    minWidth: `${minWidth}px`,
    sortable,
  } as Column
}

export {
  settingListFieldsToColumns,
}